{extend name='table'}

{block name="content"}
<div class="layui-tab layui-tab-card" style="margin-top: 0;">
    <div class="layui-tab-content">
        {include file='/warehouse/warehouse_location/index_search'}
        <table id="WarehouseLocation" data-url="{:sysuri('')}" data-target-search="form.form-search"></table>
    </div>
</div>
{/block}

{block name="script"}
<script>
    $(function () {
        $('#WarehouseLocation').layTable({
            toolbar: '#toolbarDemo',
            even: true, height: 'full',
            sort: {field: 'sort', type: 'desc'},
            cols: [[
                {checkbox: true, fixed: true},
                /** {if $super} **/
                {field: 'company_name', title: '{:lang("公司")}', minWidth: 130, align: 'center'},
                /** {/if} **/
                {field: 'sort', title: '{:lang("排序")}', align: 'center', width: 70, sort: true },
                {field: 'warehouse_c_name', title: '{:lang("仓库名称")}', align: 'center', minWidth: 120 },
                {field: 'region_name', title: '{:lang("区域名称")}', align: 'center', minWidth: 120 },
                {field: 'region_code', title: '{:lang("区域编码")}', align: 'center', width: 100, sort: true },
                {field: 'shelves_num', title: '{:lang("货架数量")}', align: 'center', width: 80 },
                {field: 'shelves_origin_num', title: '{:lang("货架起始号")}', align: 'center', width: 110},
                {field: 'layers_num', title: '{:lang("层数")}', align: 'center', width: 70 },
                {field: 'layers_num', title: '{:lang("层数起始号")}', align: 'center',width:110 },
                {field: 'inventory_capacity', title: '{:lang("库存容量")}', align: 'center',width: 80 },
                {field: 'shelves_type', title: '{:lang("货架类型")}', align: 'center', width: 90 },
                {field: 'show_tier', title: '{:lang("显示层数")}', align: 'center', width: 80 },
                {field: 'status', title: '{:lang("状态")}', align: 'center', width: 70 },
                {field: 'create_at', title: '{:lang("添加时间")}', align: 'center', width: 150, sort: true},
                {toolbar: '#toolbar', title: '{:lang("操作面板")}', align: 'center', width: 220, fixed: 'right'}
            ]]
        });

        // 单元格工具事件
        layui.table.on('tool(WarehouseLocation)', function(obj){
            var data = obj.data; // 得到当前行数据
            var layEvent = obj.event; // 获得元素对应的 lay-event 属性值

            // 根据 lay-event 的值执行不同操作
            if(layEvent === 'print_region'){ //打印
                $.ajax({
                    url: '{:url("print_region")}',
                    type: 'post',
                    dataType: "json",
                    data: {id: data.id},
                    beforeSend:(res)=>{indexload = layer.load(3, {shade: [0.1,'#fff']});},  //0.1透明度的白色背景
                    complete:(res)=>{layer.close(indexload);},
                    success: function (res) {
                        if(res.code == 1){
                            //初始化打印插件
                            hiprint.init();
                            // 打印模板
                            let json = {"panels":[{"index":0,"height":40,"width":80,"paperHeader":-16.5,"paperFooter":113.38582677165356,"printElements":[{"options":{"left":51,"top":13.5,"height":9.75,"width":120,"field":"location_code","testData":"CC-33-1-1","fontSize":21.75,"fontWeight":"bolder","textAlign":"center"},"printElementType":{"type":"text"}},{"options":{"left":37.5,"top":37.5,"height":31.5,"width":148.5,"field":"location_code","testData":"CC-33-1-1","textType":"barcode","hideTitle":true},"printElementType":{"type":"text"}},{"options":{"left":51,"top":84,"height":9.75,"width":120,"field":"location_code","testData":"CC-33-1-1","fontSize":15,"fontWeight":"bold","textAlign":"center"},"printElementType":{"type":"text"}}],"paperNumberLeft":196,"paperNumberTop":91,"paperNumberDisabled":true}]}

                            // 打印渲染数据
                            let jsonData = res.data.jsonData;

                            // 实例化并打印
                            var hiprintTemplate = new hiprint.PrintTemplate({ template:  json});
                            hiprintTemplate.print(jsonData);
                        }
                    }
                });
            }
        });
    });
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        {if auth("add")}
        <button data-modal='{:url("add")}' data-width="90%" data-title="{:lang('添加')}" class='layui-btn layui-btn-sm'>{:lang('添 加')}</button>
        {/if}
        {if auth("remove")}
        <a data-confirm="{:lang('确定要删除吗？')}" data-table-id="WarehouseLocation" data-action="{:url('remove')}" data-rule="id#{id}" class='layui-btn layui-btn-sm layui-btn-danger'>{:lang('批量删除')}</a>
        {/if}
    </div>
</script>
<script type="text/html" id="toolbar">
    {if auth("locationIndex")}
    <a class="layui-btn layui-btn-primary layui-btn-xs" data-event-dbclick  data-area = "['1200px','90%']" data-title="{:lang('查看')}" data-modal='{:url("locationIndex")}?id={{d.id}}'>{:lang('查看')}</a>
    {/if}
    {if auth("edit")}
    <a class="layui-btn layui-btn-xs" data-title="{:lang('编辑')}" data-width="90%" data-modal='{:url("edit")}?id={{d.id}}' >{:lang('编 辑')}</a>
    {/if}
    {if auth("remove")}
    <a class="layui-btn layui-btn-xs layui-btn-danger" data-confirm="{:lang('确定要永久删除吗？')}" data-action="{:url('remove')}" data-value="id#{{d.id}}">{:lang('删 除')}</a>
    {/if}
    <!--{if auth('print_region')}-->
    <a lay-event="print_region" class='layui-btn layui-btn-xs layui-btn-primary'>{:lang('打印')}</a>
    <!--{/if}-->
</script>
{/block}
